<!DOCTYPE html>
<html lang="zh-cn">
 
<head>
    <meta charset="utf-8">
	<base href="../../">
	<title>启动流程 - Powered By jiadao</title>
	<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
	<meta name="renderer" content="webkit"><meta http-equiv="X-UA-Compatible" content="IE=8,IE=9,IE=10" />
	<meta http-equiv="Expires" content="0"><meta http-equiv="Cache-Control" content="no-cache"><meta http-equiv="Cache-Control" content="no-store">
	<script src="js/jquery-1.8.3.min.js" type="text/javascript"></script>
	<link href="css/bootstrap.min.css" type="text/css" rel="stylesheet" />

	<link href="css/jquery.dataTables.min.css" type="text/css" rel="stylesheet" />
	<script src="js/jquery.dataTables.min.js" type="text/javascript"></script> 
	
	<script src="js/Sortable.js" type="text/javascript"></script>
	<script src="js/common.js" type="text/javascript"></script>
	<script src="js/vue.js"></script>

</head>
<body>

		<div id="app">
			
			<div class="container">
				<!-- <div id="addForm">

				</div> -->
		
			<form id="inputForm" class="form"  method="post" onsubmit="return false;">
				
				<fieldset>
					<legend>请假信息</legend>
					<div class="form-group">
						<label class="control-label">姓名:</label>
						<div class="controls">
							<input v-model="name" value='zhangsan'  placeholder="姓名" class=" form-control required"  type="text" maxlength="200"/>
						</div>
					</div>
					<div class="form-group">
						<label class="control-label">人员Id:</label>
						<div class="controls">
							<input v-model="user_id" value='1'  placeholder="人员Id" class=" form-control required"  type="text" maxlength="200"/>
						</div>
					</div>
					<div class="form-group">
						<label class="control-label">请假天数:</label>
						<div class="controls">
							<input v-model="day"  value='3' placeholder="请假天数" class=" form-control required"  type="text" maxlength="200"/>
						</div>
					</div>
					<div class="form-group">
						<label class="control-label">请假事由:</label>
						<div class="controls">
							<input v-model="reason"   value='有事' placeholder="请假事由" class=" form-control required" type="text"  maxlength="200"/>
						</div>
					</div>
					
			</form>

			
				<div class="form-actions">
					<input type="hidden" v-model="title"/>
					<input id="btnSubmit" @click="createProcess" class="btn btn-primary" type="button"  value="保存并提交审批"/>&nbsp;
				</div>
			</div>
		</div>
</body>

<script type="text/javascript">

	var data_save_url = 'http://localhost:8088/api/save/saveLeave'
	var data_edit_instanceid_url = 'http://localhost:8088/api/edit/editLeaveInstanceid'

	var data ={
		id:0,
		name:'张三',
		user_id:'1',
		day:'3',
		reason:'有事',
		instance_title:''
	}
	var processKey
	var app = new Vue({
		el: '#app',
		data: data,

		mounted:function(){
			// $("#addForm").load(data_form_url)
			console.log('========')
			processKey = getUrlParam("processKey")
			
			
		},
		methods:{
			createProcess:function()  {
				
				data['instance_title'] = app.title
				$.ajax({
					type:'post',
					url:data_save_url,
					data:JSON.stringify(data) ,
					contentType:"application/json;charset=UTF-8",
					success:function(ret){
						console.log(ret);
						if(ret.code==CODE_SUCCESS){
							var dataId = app.id = ret.data;
							//alert('创建成功:'+dataId)
							$.ajax({ 
								type:'post',
								url:'process/apply/'+processKey+'/'+dataId,
								data:JSON.stringify(data) ,
								contentType:"application/json;charset=UTF-8",
								success:function(ret2){
									console.log(ret2);
									if(ret2.code==CODE_SUCCESS){
										var instanceId = ret2.data
										//alert('提交流程成功+'+instanceId)
										var params = {id:dataId,instance_id:instanceId}
										$.ajax({
											type:'post',
											url:data_edit_instanceid_url,
											data:JSON.stringify(params) ,
											contentType:"application/json;charset=UTF-8",
											success:function(ret3){
												console.log(ret3);
												if(ret3.code==CODE_SUCCESS){
													alert('创建并提交审批成功')
													//alert('更新instance_id成功')
												}
											}
										})
									}
								}
							})
						}
						else{
							alert('创建失败：'+ret.msg)
						}
					},
					error:function () {
						alert('发生错误：')
					}
				});
			}
		},
		computed:{
			title:function(){
				return "申请人："+data.name+" 申请原因： "+data.reason +' 请假天数：'+data.day+"天"
			}
		}
	})
</script>
</html>